package com.kgame5.xtank3d.helper {
import com.kgame5.xtank3d.vo.MetaConfigVO;
import com.kgame5.xtank3d.vo.tank.AIMetaVO;
import com.kgame5.xtank3d.vo.tank.BodyMetaVO;

/**
 * @author kk
 */
public class MetaConfigXMLReader {
	public function read(myXML:XML):MetaConfigVO{
		
		var vo:MetaConfigVO=new MetaConfigVO();
		
		
		for each(var metaXML:XML in myXML.ai_meta_list.ai_meta){
			var aiMetaVO:AIMetaVO=readAIMetaVO(metaXML);
			vo.dict_aiDef[aiMetaVO.metaID]=aiMetaVO;
		}
		
		for each(var metaXML:XML in myXML.body_meta_list.body_meta){
			var bodyMetaVO:BodyMetaVO=readBodyMetaVO(metaXML);
			vo.dict_bodyDef[bodyMetaVO.metaID]=bodyMetaVO;
		}
		
		return vo;
	}
		
		
	private function readAIMetaVO(x:XML):AIMetaVO{
		var vo:AIMetaVO=new AIMetaVO();
		vo.metaID=parseInt(x.@meta_id);
		vo.coin=parseInt(x.@coin);
		
		vo.mov_think_interval_min=parseInt(x.mov_think_interval_min.@value);
		vo.mov_think_interval_max=parseInt(x.mov_think_interval_max.@value);
		vo.mov_action_rate_wander=parseInt(x.mov_action_rate_wander.@value);
		vo.mov_action_rate_hunt=parseInt(x.mov_action_rate_hunt.@value);
		vo.mov_wander_dur_min=parseInt(x.mov_wander_dur_min.@value);
		vo.mov_wander_dur_max=parseInt(x.mov_wander_dur_max.@value);
		//vo.hunt_dur_min,
		//vo.hunt_dur_max
		vo.mov_hunt_aim_dist=parseInt(x.mov_hunt_aim_dist.@value);
		//vo.mov_hunt_hp_rate=
		vo.atk_think_interval_min=parseInt(x.atk_think_interval_min.@value);
		vo.atk_think_interval_max=parseInt(x.atk_think_interval_max.@value);
		vo.atk_action_rate_just_fire=parseInt(x.atk_action_rate_just_fire.@value);
		vo.atk_action_rate_kill_fire=parseInt(x.atk_action_rate_kill_fire.@value);
		vo.atk_alarm_range=parseInt(x.atk_alarm_range.@value);
		vo.test_hit_dur_ms=parseInt(x.test_hit_dur_ms.@value);
			
		return vo;
	}
	private function readBodyMetaVO(x:XML):BodyMetaVO{
		var vo:BodyMetaVO=new BodyMetaVO();
		vo.metaID=parseInt(x.@meta_id);
		vo.coin=parseInt(x.@coin);
		
		vo.MOV=parseInt(x.MOV.@value);
		vo.HUNT_MOV=parseInt(x.HUNT_MOV.@value);
		vo.cannonY=parseInt(x.cannonY.@value);
		vo.ReloadShotMS=parseInt(x.ReloadShotMS.@value);
		
		vo.HP=parseInt(x.HP.@value);
		vo.DEF=parseInt(x.DEF.@value);
		vo.bornDurMS=parseInt(x.bornDurMS.@value);
		vo.hurtDurMS=parseInt(x.hurtDurMS.@value);
		
		vo._A=parseInt(x.bounds.@A);
		vo._B=parseInt(x.bounds.@B);
		vo._H2=parseInt(x.bounds.@H2);
		vo._R=parseInt(x.bounds.@R);
		
		
		return vo;
	}
	
}//end of class
}
